package etc

import (
	"fmt"
	"io/ioutil"
	"path"
	"strings"
)

var files []string

// 获取目录文件
func GetFiles(dir string, first ...bool) ([]string, error) {
	if len(first) <= 0 {
		files = []string{}
	}

	dir = strings.TrimRight(dir, PATH())

	fn, err := ioutil.ReadDir(dir)
	if err != nil {
		return files, err
	}

	for _, file := range fn {
		fileName := file.Name()
		if fileName == "." || fileName == ".." || fileName == ".git" {
			continue
		}

		if file.IsDir() {
			GetFiles(fmt.Sprintf("%s%s%s", dir, PATH(), fileName), false)
		} else {
			if EXT(path.Ext(fileName)) {
				files = append(files, fmt.Sprintf("%s%s%s", dir, PATH(), fileName))
			}
		}
	}

	return files, nil
}
